﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Long.DAL
{
    public static class DB
    {
        //依赖注入的方式，生成数据库
        public static ISqlSugarClient SqlSugarClient { set; get; }
        public static void AddSqlsugarSetup(this IServiceCollection services, SqlSugar.DbType dbType, string conn)
        {

            //注册SqlSugar用AddScoped
            services.AddScoped<ISqlSugarClient>(s =>
            {
                //Scoped用SqlSugarClient 
                SqlSugarClient = new SqlSugarClient(new ConnectionConfig()
                {
                    DbType = dbType,
                    ConnectionString = conn,
                    IsAutoCloseConnection = true,
               });
                return SqlSugarClient;
            });
        }
    }
}
